package com.zizy.healthexpert.Activity;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

import com.zizy.healthexpert.Adapter.listHistoryAdapter;
import com.zizy.healthexpert.Database.MyDatabase_DishesRecords;
import com.zizy.healthexpert.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class HistoryActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        listHistoryAdapter adapter;
        /*get View*/
        ListView listHistory=(ListView)findViewById(R.id.listHistory);
        ArrayList<Object> list;
        List<listHistoryAdapter.History> listForAdapter=new ArrayList<listHistoryAdapter.History>();
            /*open*/
        MyDatabase_DishesRecords myDatabase_dishesRecords=new MyDatabase_DishesRecords(this);
        list=myDatabase_dishesRecords.SearchDatabase("*");
            /*close*/
        myDatabase_dishesRecords.close();
        for (int i = 0; i < list.size(); i++) {
            MyDatabase_DishesRecords.DishesRecords re=(MyDatabase_DishesRecords.DishesRecords)list.get(i);
            listHistoryAdapter.History temp=new listHistoryAdapter.History(re.getDishesName(),re.getDate());
            listForAdapter.add(temp);
        }
        /*set view*/
        adapter = new listHistoryAdapter(this,R.layout.list_histroy ,listForAdapter);
        listHistory.setAdapter(adapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.history, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
